home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!pipeline!not-for-mail
- From: digiulio@nyc.pipeline.com (Thomas DiGiulio)
- Newsgroups: comp.lang.c++,
- Subject: Re: Fastest Sorting Algorithm?
- Date: 4 Apr 1996 23:12:43 -0500
- Organization: The Pipeline
- Message-ID: <4k26jr$1cj@pipe10.nyc.pipeline.com>
- References: <DpAxtI.3w9@undergrad.math.uwaterloo.ca>
- NNTP-Posting-Host: pipe10.nyc.pipeline.com
- X-PipeUser: digiulio
- X-PipeHub: nyc.pipeline.com
- X-PipeGCOS: (Tom DiGiulio)
- X-Newsreader: Pipeline v3.5.0
-
- On Apr 03, 1996 19:51:18 in article <Re: Fastest Sorting Algorithm?>,
- 'sckettle@undergrad.math.uwaterloo.ca (Steve Kettle)' wrote:
-
-
- >In article <Dou55w.7MB@novice.uwaterloo.ca>,
- >Gerald Wang <GTWANG@HELIX.Watstar.UWaterloo.CA> wrote:
- >>A classmate was recently asked during a job interview what is the fastest
-
- >>method to sort an array of numbers. He replied "Use a quicksort." They
- >>asked "And how would you make it faster still?" He couldn't come up with
-
- >>much...end of interview.
- >>
- >>I know it's a vague question... Any ideas on what they were asking? Or
- >>what the right answer is?
- >>
- >>Gerald
- >>
- >>-------------------------------------------------------------------------
-
- >>Gerald Wang
- >>http://www.csclub.uwaterloo.ca/~gtwang
- >>
- >>
- >
- >Well you could use a type of bucket sorting algorithm which is faster than
-
- >quicksort when sorting integers. How to make it faster I don't know - you
-
- >don't really make algortithms faster you make code implementations of
- >algorithms faster. Mybe they meant tweaking stratigies for quicksort like
- how
- >to choose a pivot element. Who knows.
- >
-
- I came upon this question, and decided to do a liitle research. Sitting on
- my bookshelf was a good book (IMHO) that I had used
- in an "Analysis of Algorithms" course - "Data Structures and Algorithms" by
- Aho, Hopcroft, and Ullman.
-
- In a section entitled "Improvements to Quicksort" (p.270) they mention that
- the quicksort is indeed fast, and "its running time is less than that of
- all other currently known O(n log n) sorting algorithms..."
-
- In the average case it is on the O(n log n), and degrades to O(n^2) in the
- worst case.
-
- Briefly, among the improvements that can be made:
-
- 1) devise a way to pick pivot elements that divide the subarrays so that
- each subarray has relatively the same # of elements.
-
- 2) If you are willing to sacrifice space for time, create an array of
- pointers, which point to the records in the array. Move the pointers in
- the same manner as the quicksort would move the records, and the pointers
- would point to the records in sorted order.This would reduce the number of
- swaps from O(n log n) to n.
-
- I hope this paraphrase made sense. Hope this helped.
-
- Tom
- --
- digiulio@pipeline.com
-